package com.example.reference_book.controller;

import com.example.reference_book.entity.Course;
import com.example.reference_book.controller.CourseStrategy;
import com.example.reference_book.controller.searchNameStrategy;
import com.example.reference_book.controller.searchTagStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("SearchCourseUtil")
public class SearchCourseUtil {

    @Resource
    private searchNameStrategy searchName;

    @Resource
    private searchTagStrategy searchTag;

    @Resource
    private CourseStrategy courseStrategy;



//    public static SearchCourseUtil searchCourseUtil=new SearchCourseUtil();
    private SearchCourseUtil (){}

//    public static SearchCourseUtil getSearchCourseUtil() {
//        return searchCourseUtil;
//    }

    @GetMapping("/{type}/{key}")
    public List<Course> search(@PathVariable("type") String type, @PathVariable("key") String key){
        System.out.println("type: "+type);
        if(type.equals("名称")){
            System.out.println("name");
            this.courseStrategy = this.searchName;
        }else{
            this.courseStrategy = this.searchTag;
            System.out.println("tag");
        }
        return this.courseStrategy.searchByType(type,key);
    }
}
